package com.kgc.scd.service.impl;

import com.kgc.scd.bean.Sign;
import com.kgc.scd.bean.SignExample;
import com.kgc.scd.bean.SignVO;
import com.kgc.scd.mapper.SignMapper;
import com.kgc.scd.service.SignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created On : 2022/6/15.
 * <p>
 * Author     : nainai
 * <p>
 * Description: 签到服务接口实现类
 */
@Slf4j
@Service
public class SignServiceImpl implements SignService {

    @Autowired(required = false)
    private SignMapper signMapper;

    @Override
    public boolean addSign(Sign sign) {
        return signMapper.insertSelective(sign) > 0;
    }

    @Override
    public List<Sign> queryUserSignRecord(String userId, Integer year, Integer month) {
        SignExample signExample = new SignExample();
        SignExample.Criteria criteria = signExample.createCriteria();

        // 定义查询条件
        criteria.andSignYearEqualTo(year).andUserIdEqualTo(userId);
        if (!(month == null)) {
            criteria.andSignMonthEqualTo(month);
        }

        return signMapper.selectByExample(signExample);
    }
}
